package com.sichen.search.controller;

import com.sichen.search.service.MallSearchService;
import com.sichen.search.vo.SearchParam;
import com.sichen.search.vo.SearchResult;
import org.elasticsearch.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 检索服务跳转controller
 * <p>Created with IntelliJ IDEA.
 * <p>Author: 思尘
 * <p>Created time: 2022-09-17 15:59
 * <p>Version: V1.0
 */
@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;

    /**
     * 自动将页面提交过来的所有请求参数封装成指定的对象
     * @param searchParam 检索的条件
     * @return 返回检索后的数据
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam , Model model , HttpServletRequest request){
        // 1.根据传递过来的页面的查询参数 , 去es中检索商品
        searchParam.set_queryString(request.getQueryString());
        SearchResult result = mallSearchService.search(searchParam);
        model.addAttribute("result",result);
        return "list";
    }
}
